from django.shortcuts import render

from django.views import View

from goods.models import ContentCategory
from meiduo_mall.utils.my_category import get_categories


class IndexView(View):
    def get(self, request):
        categories = get_categories()
        contents = {}
        content_categories = ContentCategory.objects.all()
        for content_category in content_categories:
            contents[content_category.key] = content_category.content_set.order_by('sequence')
        context = {
            "categories": categories,
            "contents": contents
        }
        return render(request, 'index.html', context=context)
